package com.ruoyi.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.GoodsSpuInfo;
import com.ruoyi.service.IGoodsSpuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/webshop/goodsSpuInfo")
public class GoodsSpuInfoController extends BaseController {

    @Autowired
    private IGoodsSpuInfoService goodsSpuInfoService;

    /**
     * 查所有
     */
    @GetMapping("/list")
    public AjaxResult selectAll() {
        List<GoodsSpuInfo> list = goodsSpuInfoService.selectAll();
        return AjaxResult.success(list);
    }

    /**
     * 根据id 查一条
     */
    @GetMapping("/{id}")
    public AjaxResult selectById(@PathVariable() Long id) {
        GoodsSpuInfo goodsSpuInfo = goodsSpuInfoService.selectById(id);
        return AjaxResult.success(goodsSpuInfo);
    }

    /**
     * 查分页
     */
    @GetMapping("/page")
    public TableDataInfo selectPage(GoodsSpuInfo goodsSpuInfo) {
        startPage();
        List<GoodsSpuInfo> list = goodsSpuInfoService.selectPage(goodsSpuInfo);

        return getDataTable(list);
    }
    /**
     * 添加
     */
    @PostMapping()
    public AjaxResult insertOne(@RequestBody GoodsSpuInfo goodsSpuInfo) {
        int i = goodsSpuInfoService.insertOne(goodsSpuInfo);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    /**
     * 修改
     */
    @PutMapping()
    public AjaxResult updateById(@RequestBody GoodsSpuInfo goodsSpuInfo) {
        int i = goodsSpuInfoService.updateById(goodsSpuInfo);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    /**
     * 删除
     */
    @DeleteMapping("/{ids}")
    public AjaxResult deleteByIds(@PathVariable() Long[] ids) {
        int i = goodsSpuInfoService.deleteByIds(ids);
        if (i > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
}